package com.csu.csumall.VO;

import com.csu.csumall.entity.Order;
import com.csu.csumall.entity.User;
import com.fasterxml.jackson.annotation.JsonIgnore;

import java.math.BigInteger;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;


public class NewOrderVO {

    private Integer shippingId;
    private List<OrderProductVO> OrderProductVOList = new ArrayList<>();

    public Order getOrder(User user) {
        Order order = new Order(user.getId());
        order.setOrderNo(this.getOrderNo());
//        order.setUserId();
        order.setShippingId(shippingId);
        order.setCreateTime(LocalDateTime.now());
        return null;
    }

    @JsonIgnore
    private BigInteger getOrderNo() {
        LocalDateTime localDateTime = LocalDateTime.now();
        String timeStr = localDateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmSS"));
        Integer randNum = new Random().nextInt(999999);
        return new BigInteger(timeStr + randNum);
    }
}
